package com.team.party.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.team.party.bean.Activity;
import com.team.party.bean.Ajst;
import com.team.party.bean.Sjst;
import com.team.party.bean.Society;
import com.team.party.bean.Student;
import com.team.party.mapper.StudentMapper;
import com.team.party.service.StudentService;
@Service
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentMapper studentmapper;
	
	@Override
	public Student serchStudent(String username) throws Exception {
		Student student = new Student();
		student.setStu_username(username);
		return studentmapper.serchStudent(student);
		// TODO Auto-generated method stub
		
	}

	@Override
	public Boolean register(String stu_name, String stu_sex, int stu_age, String stu_no, String stu_username,
			String stu_password, String stu_tel, String stu_form, String stu_scho) throws Exception {
		// TODO Auto-generated method stub
		Student student = new Student();
		student.setStu_name(stu_name);
		student.setStu_sex(stu_sex);
		student.setStu_age(stu_age);
		student.setStu_no(stu_no);
		student.setStu_username(stu_username);
		student.setStu_password(stu_password);
		student.setStu_tel(stu_tel);
		student.setStu_form(stu_form);
		student.setStu_scho(stu_scho);

		return studentmapper.saveStudent(student);
	}

	@Override
	public void logout() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Student serchMessage(String stu_no) throws Exception {
		// TODO Auto-generated method stub
		Student student = new Student();
		student.setStu_no(stu_no);

		return studentmapper.serchMessage(student);
	}

	@Override
	public Boolean changeMessage(String stu_name, String stu_sex, int stu_age, String stu_tel, String stu_form,
			String stu_scho, String stu_no) throws Exception {
		// TODO Auto-generated method stub
		
		Student student = new Student();
		student.setStu_name(stu_name);
		student.setStu_sex(stu_sex);
		student.setStu_age(stu_age);
		student.setStu_tel(stu_tel);
		student.setStu_form(stu_form);
		student.setStu_scho(stu_scho);
		student.setStu_no(stu_no);
		
		return studentmapper.changeMessage(student);
	}

	@Override
	public Boolean changePassword(String stu_no, String stu_password) throws Exception {
		// TODO Auto-generated method stub
		
		Student student = new Student();
		
		student.setStu_no(stu_no);
		student.setStu_password(stu_password);
		
		return studentmapper.changePassword(student);
	}

	@Override
	public List<Society> serchSociety() throws Exception {
		// TODO Auto-generated method stub

		return studentmapper.serchSociety();
	}

	@Override
	public Boolean joinSociety(String stu_no, String soc_no) throws Exception {
		// TODO Auto-generated method stub
		Sjst sjst = new Sjst();
		
		sjst.setStu_no(stu_no);
		sjst.setSoc_no(soc_no);
		sjst.setSjst_start(new Date());
		
		return studentmapper.joinSociety(sjst);
	}

	@Override
	public List<Society> serchJoinedSociety(String stu_no) throws Exception {
		// TODO Auto-generated method stub
		Student student = new Student();
		student.setStu_no(stu_no);
		
		return studentmapper.serchJoinedSociety(student);
	}

	@Override
	public Boolean exitSociety(String stu_no, String soc_no) throws Exception {
		// TODO Auto-generated method stub
		Sjst sjst = new Sjst();
		sjst.setStu_no(stu_no);
		sjst.setSoc_no(soc_no);
		
		return studentmapper.exitSociety(sjst);
	}

	@Override
	public List<Activity> serchActivity() throws Exception {
		// TODO Auto-generated method stub

		return studentmapper.serchActivity();
	}

	@Override
	public Boolean joinActivity(String stu_no, String act_no) throws Exception {
		// TODO Auto-generated method stub
		Ajst ajst = new Ajst();
		ajst.setStu_no(stu_no);
		ajst.setAct_no(act_no);
		ajst.setAjst_start(new Date());
		
		return studentmapper.joinActivity(ajst);
	}

	@Override
	public List<Activity> serchJoinedActivity(String stu_no) throws Exception {
		// TODO Auto-generated method stub
		Student student = new Student();
		student.setStu_no(stu_no);
		
		return studentmapper.serchJoinedActivity(student);
	}

	@Override
	public Boolean exitActivity(String stu_no, String act_no) throws Exception {
		// TODO Auto-generated method stub
		Ajst ajst = new Ajst();
		ajst.setStu_no(stu_no);
		ajst.setAct_no(act_no);

		return studentmapper.exitActivity(ajst);
	}

	@Override
	public List<Society> serchSocietyByFuzzy(String soc_no, String soc_name) throws Exception {
		// TODO Auto-generated method stub
		return studentmapper.serchSocietyByFuzzy(soc_no, soc_name);
	}

	@Override
	public List<Activity> serchActivityByFuzzy(String act_no, String act_name) throws Exception {
		// TODO Auto-generated method stub
		return studentmapper.serchActivityByFuzzy(act_no, act_name);
	}
}
